<?php
/*
 *    Prototyp-Ro
 *    Copyright (C) 2011  Patton
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Class User_Connection extends Main_Utils{
    function log_in($username, $psswd_user){
        $this->return=array();
    	$this->query = sprintf("SELECT `account_id`, `userid`, `sex`, `email`, `level`, `state` FROM `login` WHERE `userid` = '%s' AND `user_pass` = '%s'", mysql_real_escape_string($username), md5($psswd_user));
        $this->result = mysql_query($this->query);
        $this->row  = mysql_fetch_assoc($this->result);

        if($this->row['status']  > 0){
            $this->return[] = _CL_BANNED;
        }else
	if (mysql_num_rows($this->result) == 1){
            $_SESSION['log_in'] = 1;
            $_SESSION['account_id'] = $this->row['account_id'];
            $_SESSION['userid'] = $this->row['userid'];
            $_SESSION['email'] = $this->row['email'];
            $_SESSION['sex'] = $this->row['sex'];
            $_SESSION['level'] = $this->row['level'];
        }
        else{
            $this->log_out();
            $this->return[] = _CL_INCORRECT_USERNAME;
        }
        return Main_utils::print_return_array($this->return);
    }
    function log_out(){
            session_start();
            $_SESSION = array();
            session_destroy();
            return;
    }
}
$User_Connection = new User_Connection();
?>